﻿using Db7;
using Db7_ut.DomainObjects;
using System.Html;
using System;

namespace Db7_ut.Views.SingleElementBinding
{
    public class IntBindingTest
    {
        private Employee _emp;

        public IntBindingTest(string ContainerID)
        {
            _emp = new Employee();
            _emp.Age = 27;


            VirtualElement veParent = new VirtualElement(); veParent.Tag = "span";
            VirtualElement veCommand = new VirtualElement();
            {
                veCommand.Tag = "span";
                veCommand.Text = "Increment";
                veParent.ChildrenNN.Add(veCommand);
                RenderContext.RegisterOnClickHandler(veCommand, OnClickCommand);
            }
            VInput txtBox = new VInput(); veParent.Children.Add(txtBox);
            txtBox.Value_DB = new StringBinder(null);
            txtBox.Value_DB.SetIntInnerBinder(_emp.AgeDB);
            veParent.RenderInside(ContainerID);
        }

        private void OnClickCommand(ElementEvent e)
        {
            int newAge = _emp.Age + 1;
            _emp.Age = newAge;
        }
    }
}
